<template>
	<view class="container">
		<view class="tui-addr-box">
			<form :report-submit="true" v-if="isauth">
				<tui-list-cell :hover="false" padding="0">
					<view class="tui-line-cell">
						<view class="tui-title">真实姓名</view>
						<input placeholder-class="tui-phcolor" class="tui-input" v-model="isauth.real_name" disabled placeholder="请输入真实姓名提现姓名唯一" maxlength="50" type="text" />
					</view>
				</tui-list-cell>
				<tui-list-cell :hover="false" padding="0">
					<view class="tui-line-cell">
						<view class="tui-title">身份证号</view>
						<input placeholder-class="tui-phcolor" class="tui-input" v-model="isauth.id_card" disabled="" placeholder="请输入身份证号" maxlength="18" type="text" />
					</view>
				</tui-list-cell>
			

				
			</form>
			<form :report-submit="true" v-else>
				<tui-list-cell :hover="false" padding="0">
					<view class="tui-line-cell">
						<view class="tui-title">真实姓名</view>
						<input placeholder-class="tui-phcolor" class="tui-input" v-model="real_name" placeholder="请输入真实姓名提现姓名唯一" maxlength="50" type="text" />
					</view>
				</tui-list-cell>
				<tui-list-cell :hover="false" padding="0">
					<view class="tui-line-cell">
						<view class="tui-title">身份证号</view>
						<input placeholder-class="tui-phcolor" class="tui-input" v-model="id_card" placeholder="请输入身份证号" maxlength="18" type="text" />
					</view>
				</tui-list-cell>
				
				<!-- 保存地址 -->
				<view class="tui-btn__box">
					<view class="tui-addr-save">
						<tui-button shadow type="danger" height="88rpx" shape="circle" @click="submit">点击提交</tui-button>
					</view>
				</view>
				
			</form>
		</view>
	</view>
</template>
<script>
	import {
		pathToBase64,
		base64ToPath
	} from 'image-tools'
export default {
	data() {
		return {
			real_name: "",
			id_card:"",
			front_id_card:'',
			back_id_card:'',
			imgarr:[],
			isdisabled:false,
			isloading:false,
			isauth:''
		};
	},
	onShow() {
		this.tui.haslogin();
		if(this.tui.isLogin()){
			this.init();
		}
	},
	methods: {
		init(){
			/* 是否实名认证 */
			let token = this.tui.getToken();
			let authData={token: token};
			let isauth = this.tui.request('user', 'post',authData, 1000, 1, '', 'getRealNames');
			Promise.resolve(isauth).then((value) => {
				if (value.data) {
					this.isauth=value.data;
				}
			})
		},
		chooseImageIdcard: async function() {
			uni.chooseImage({
				sizeType: ['original', 'compressed'],
				sourceType: ['album', 'camera'],
				count: 1,
				success: (res) => {
					let max_size=5*1024*1024;
					if (res.tempFiles[0].type.indexOf("image") < 0) {                
					   this.tui.toast("请选择图片类型的文件");
					   return;
					}
					if(res.tempFiles[0].size>=max_size){
						this.tui.toast("上传图片不能超过5M");
						return;
					}
					this.front_id_card = res.tempFilePaths;
					let token = this.tui.getToken();
					
					let datas={
						token: token,
						image:res.tempFiles[0].name,
						img_type:2,
					};
					let uper = this.tui.uploadFile('imgs',datas,res.tempFilePaths[0],'uploadImg');
                    Promise.resolve(uper).then((value)=>{
						
					   if(value.code==10000){
					   	this.imgarr.push(value.data.file_path);
					   }else{
					   	this.tui.toast(value.message);
					   }
					})
					
				},
				fail: (err) => {
					// #ifdef APP-PLUS
					if (err['code'] && err.code !== 0 && this.sourceTypeIndex === 2) {
						this.checkPermission(err.code);
					}
					// #endif
					// #ifdef MP
					// #endif
				}
			})
		},
		chooseImageBackCard: async function() {
			uni.chooseImage({
				sizeType: ['original', 'compressed'],
				sourceType: ['album', 'camera'],
				count: 1,
				success: (res) => {
					let max_size=5*1024*1024;
					if (res.tempFiles[0].type.indexOf("image") < 0) {                
					   this.tui.toast("请选择图片类型的文件");
					   return;
					}
					if(res.tempFiles[0].size>=max_size){
						this.tui.toast("上传图片不能超过5M");
						return;
					}
					this.back_id_card = res.tempFilePaths;
				
					let token = this.tui.getToken();
					
					let datas={
						token: token,
						image:res.tempFiles[0].name,
						img_type:2,
					};
					let uper = this.tui.uploadFile('imgs',datas,res.tempFilePaths[0],'uploadImg');
					Promise.resolve(uper).then((value)=>{
						
					   if(value.code==10000){
					   	this.imgarr.push(value.data.file_path);
					   }else{
					   	this.tui.toast(value.message);
					   }
					})
				},
				fail: (err) => {
					// #ifdef APP-PLUS
					if (err['code'] && err.code !== 0 && this.sourceTypeIndex === 2) {
						this.checkPermission(err.code);
					}
					// #endif
					// #ifdef MP
					// #endif
				}
			})
		},
		
		submit(){
			this.isloading=true;
			this.isdisabled=true;
			let token = this.tui.getToken();
			let datas={
				token: token,
				id_card:this.id_card,
				real_name:this.real_name,
				// front_id_card:this.imgarr[0],
				// back_id_card:this.imgarr[1],
			};
			let idcard=this.tui.request('user','post',datas,1000,1,'','realName');
			Promise.resolve(idcard).then((value)=>{
			   if(value.code==10000){
			   	this.tui.toast(value.message);
				uni.switchTab({
				  url: '/pages/my/my'
				});
			   }else{
			   	this.tui.toast(value.message);
				this.isloading=false;
				this.isdisabled=false;
			   }
			})
		}
		
	},
	
};
</script>

<style>
page {
	background-color: #f7f7f7;
}

.container {
	padding-bottom: 100rpx;
	margin-top:20rpx;
	color: #333;
}
.tui-line-cell {
		width: 100%;
		padding: 24rpx 30rpx;
		box-sizing: border-box;
		display: flex;
		align-items: center;
	}

	.tui-title {
		width: 180rpx;
		font-size: 28rpx;
	}

	.tui-title-city-text {
		width: 180rpx;
		height: 40rpx;
		display: block;
		line-height: 46rpx;
	}
	
	.ag_title{margin:40rpx 40rpx 0 30rpx;display: flex;box-sizing: border-box;
		display: flex;
		align-items: center;font-size: 20rpx;}
    .uni-uploader__img{width:100%;height:100%;}
	.tui-input {
		width: 500rpx;
		font-size: 28rpx;
	}
	.agreement{color:#ff241d}
.tui-btn__box{
    width: 100%;
    padding: 20px 15px;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
}
	.tui-input-city {
		flex: 1;
		height: 40rpx;
		font-size: 28rpx;
		padding-right: 30rpx;
	}
     .fin-list{
		 justify-content: space-between;
	 }
	 .fin_img{
	 	border:1px dashed #d9d8d8;
		border-radius: 10rpx;
	 	width:146rpx;
	 	height: 146rpx;
	 	margin:1rpx 0;
	 }
	 .icon_cam{display: flex;
		justify-content: center;
		align-items: center;
		margin-top: 22rpx;}
		.fin_txt{
			font-size: 20rpx;text-align: center;color:#707070
		}
	.tui-phcolor {
		color: #ccc;
		font-size: 28rpx;
	}
	.tui-cell-title{
		font-size: 28rpx;
	}
	.tui-addr-label {
		margin-left: 70rpx;
	}

	.tui-label-item {
		width: 76rpx;
		height: 40rpx;
		border: 1rpx solid rgb(136, 136, 136);
		border-radius: 6rpx;
		font-size: 26rpx;
		text-align: center;
		line-height: 40rpx;
		margin-right: 20rpx;
		display: inline-block;
		transform: scale(0.9);
	}
	.tui-label-active{
		background: #E41F19;
		border-color:#E41F19;
		color: #fff;
	}
	.tui-swipe-cell {
		width: 100%;
		display: flex;
		justify-content: space-between;
		align-items: center;
		background: #fff;
		padding: 10rpx 24rpx;
		box-sizing: border-box;
		border-radius: 6rpx;
		overflow: hidden;
		font-size: 28rpx;
	}

	.tui-switch-small {
		transform: scale(0.8);
		transform-origin: 100% center;
	}
</style>
